from mpt_core.mpt import MerklePatriciaTree
from mpt_core.au import *
import rsa
import hashlib


MPT = MerklePatriciaTree(debug=False,from_scratch=True)
MPT.init_new_root()
print(MPT.root_hash)
roots = []
kkey = []
visit_nodes = []
for _ in range(5):
    pub,pri = rsa.newkeys(512)
    pub = pub.save_pkcs1('PEM').decode()
    k = hexdigest_to_nib(hashlib.sha256(pub.encode()).hexdigest())
    kkey.append(k)
    MPT.insert(k,pub)
    root = MPT.root_hash
    roots.append(root)
    visit_node = presense(MPT.db,k)
    print(type(visit_node))
    visit_nodes.append(visit_node)

for i in  range(5):
    a = authentication(roots[i],visit_nodes[i],kkey[i])
    print(a)


